package com.shiro.shiroweb.dao;

import com.shiro.shiroweb.entity.PermissionEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Set;

@Repository
public interface PermissionRepository extends JpaRepository<PermissionEntity,String> {
    @Query(value = "SELECT p.permission FROM permission AS p INNER JOIN ts_role_permission AS ts2 ON ts2.permission = p.id " +
            "INNER JOIN ts_user_role AS ts ON ts.role_id = ts2.role_id " +
            "INNER JOIN `user` AS u ON u.id = ts.user_id " +
            "WHERE u.name =  ?1 ",nativeQuery = true)
    Set<String> findPermissionByUsername(String username);
}
